package com.atguigui.leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * 532.数组中的 k-diff 数对
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/6/16 8:39
 */
public class P532KDiffPairsInAnArray {
    public static void main(String[] args) {
        Solution solution = new P532KDiffPairsInAnArray().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int findPairs(int[] nums, int k) {
            Set<Integer> visited = new HashSet<>();
            Set<Integer> res = new HashSet<>();
            for (int num : nums) {
                if (visited.contains(num - k)) {
                    res.add(num - k);
                }
                if (visited.contains(num + k)) {
                    res.add(num);
                }
                visited.add(num);
            }

            return res.size();

        }
    }
}
